package com.resou.reader.api.entry;

import com.resou.reader.mine.IView.UserInstance;

import java.util.Date;

/**
 * Created by Garrett on 2018/8/27.
 * contact me krouky@outlook.com
 */
public class LoginData {

    /**
     * id : 2
     * openId :
     * createTime : 1531110557255
     * lastLoginTime : null
     * userName : null
     * password : null
     * nickName : null
     * thirdQqCode : null
     * thirdWxCode : null
     * thirdSinaCode : null
     * phone : 18601381457
     * email : null
     * ic_qq : null
     * age : null
     * gender : null
     * wechart : null
     * headPic : null
     * userLevel : 0
     * userFrom : null
     * userType : null
     * userStatus : null
     */

    private int id;
    private String openId;
    private long createTime;
    private String lastLoginTime;
    private String userName;
    private String password;
    private String nickName;
    private String thirdQqCode;
    private String thirdWxCode;
    private String thirdSinaCode;
    private String phone;
    private String email;
    private String qq;
    private int age;
    private String gender;//1男2女
    private String wechart;
    private String head_pic;
    private int userLevel;
    private String userFrom;
    private String userType;
    private String userStatus;
    private String energy;
    private double giftBlance;
    private double blance;//书豆
    private String birthday;
    private Integer isVipUser;//
    private String vipEndTime;//vip到期时间
    private int readType;

    /**
     * 服务端能量值可能为null
     *
     * @return 能量值的字符串
     */
    public String getEnergy() {
        if (energy == null) {
            energy = "0";
        }
        return energy;
    }

    public void setEnergy(String energy) {
        this.energy = energy;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public double getGiftBlance() {
        return giftBlance;
    }

    public void setGiftBlance(double giftBlance) {
        this.giftBlance = giftBlance;
    }

    public double getBlance() {
        return blance;
    }

    public void setBlance(double blance) {
        this.blance = blance;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(String lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getThirdQqCode() {
        return thirdQqCode;
    }

    public void setThirdQqCode(String thirdQqCode) {
        this.thirdQqCode = thirdQqCode;
    }

    public String getThirdWxCode() {
        return thirdWxCode;
    }

    public void setThirdWxCode(String thirdWxCode) {
        this.thirdWxCode = thirdWxCode;
    }

    public String getThirdSinaCode() {
        return thirdSinaCode;
    }

    public void setThirdSinaCode(String thirdSinaCode) {
        this.thirdSinaCode = thirdSinaCode;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getQq() {
        return qq;
    }

    public void setQq(String qq) {
        this.qq = qq;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        if (gender == null || gender.equals("0")) {
            return "1";
        }
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getWechart() {
        return wechart;
    }

    public void setWechart(String wechart) {
        this.wechart = wechart;
    }

    public int getReadType() {
        return readType;
    }

    public void setReadType(int readType) {
        this.readType = readType;
    }

    /**
     * 服务端头像可能为null
     *
     * @return
     */
    public String getHead_pic() {
        if (head_pic == null) {
            head_pic = "";
        }
        return head_pic;
    }

    public void setHead_pic(String headPic) {
        this.head_pic = headPic;
    }

    public int getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(int userLevel) {
        this.userLevel = userLevel;
    }

    public String getUserFrom() {
        return userFrom;
    }

    public void setUserFrom(String userFrom) {
        this.userFrom = userFrom;
    }

    public String getUserType() {
        return userType == null ? "" : userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getUserStatus() {
        return userStatus;
    }

    public void setUserStatus(String userStatus) {
        this.userStatus = userStatus;
    }


//    public int getIsVip() {
//        if (UserInstance.getLoginData().getVipEndTime() != null && !UserInstance.getLoginData().getVipEndTime().equals("")) {
//            if (new Date().getTime() > Long.valueOf(UserInstance.getLoginData().getVipEndTime())) {
//                return 2;//过期了
//            } else {
//                return 1;
//            }
//        } else {
//            return isVip;
//        }
//    }
//
//    public void setIsVip(int isVip) {
//        this.isVip = isVip;
//    }

    public int getIsVipUser() {
        if (UserInstance.getLoginData().getVipEndTime() != null && !UserInstance.getLoginData().getVipEndTime().equals("0")) {
            if (new Date().getTime() > Long.valueOf(UserInstance.getLoginData().getVipEndTime())) {
                return 2;//过期了
            } else {
                return 1;
            }
        } else {
            return isVipUser == null ? 0 : isVipUser;
        }
    }

    public void setIsVipUser(int isVipUser) {
        this.isVipUser = isVipUser;
    }

    public String getVipEndTime() {
        return vipEndTime;
    }

    public void setVipEndTime(String vipEndTime) {
        this.vipEndTime = vipEndTime;
    }

    @Override
    public String toString() {
        return "LoginData{" +
                "id=" + id +
                ", openId='" + openId + '\'' +
                ", createTime=" + createTime +
                ", lastLoginTime='" + lastLoginTime + '\'' +
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                ", nickName='" + nickName + '\'' +
                ", thirdQqCode='" + thirdQqCode + '\'' +
                ", thirdWxCode='" + thirdWxCode + '\'' +
                ", thirdSinaCode='" + thirdSinaCode + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", qq='" + qq + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                ", wechart='" + wechart + '\'' +
                ", head_pic='" + head_pic + '\'' +
                ", userLevel=" + userLevel +
                ", userFrom='" + userFrom + '\'' +
                ", userType='" + userType + '\'' +
                ", userStatus='" + userStatus + '\'' +
                ", energy='" + energy + '\'' +
                ", giftBlance=" + giftBlance +
                ", blance=" + blance +
                ", birthday='" + birthday + '\'' +
                '}';
    }
}
